<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../common.inc" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link href="./css/style1.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="./js/form.js"></script>
<script type="text/javascript" language="javascript">
<!--
	function checkForm(message){
		var objs = document.getElementsByName("id");
		var num = 0;
		for(var i = 0; i < objs.length; i++){
			if(objs[i].checked)num = num + 1;
		}
		if(num == 0){
			alert(message);
			return false;
		}
		return true;
	}
	
	function checkForm2(){
		var objs = document.getElementsByName("id");
		var sign = 0;
		for(var i = 0; i < objs.length; i++){
			if(objs[i].value != 0 && objs[i].checked)sign = sign + 1;
		}
		if(sign <= 0){
			alert("请选择待操作的项！");
			return false;
		}else if(sign > 1){
			alert("只能选择一个待操作项！");
			return false;
		}
		return true;
	}

	function addUser(){
		window.parent.location.href = "./user.do?action=preAddUser";
		window.location.target = "main";
	}
	
	function updateUser(){
		if(checkForm2()){
			var objs = document.getElementsByName("id");
			var id = 0;
			for(var i = 0; i < objs.length; i++){
				if(objs[i].value != 0 && objs[i].checked){
					id = objs[i].value;
					break;
				}
			}
			window.parent.location.href = "./user.do?action=preUpdateUser&id="+id;
			window.location.target = "main";
		}
	}
	
	function viewUser(id){
		window.parent.location.href = "./user.do?action=viewUser&id="+id;
		window.location.target = "main";
	}
	
	function selectUserType(){
		var obj = document.getElementById("isActivity");
		document.userListForm.action = "./user.do?action=userList&isActivity="+obj.value;
		document.userListForm.target = "userListFrame";
		document.userListForm.submit();
	}
	
	function stopUsers(){
		var message = "<fmt:message key='common.message.wStop'/>";
		if(checkForm(message) && confirm("<fmt:message key='common.message.stop'/>")){
			document.userListForm.action = "./user.do?action=stopUsers";
			document.userListForm.target = "userListFrame";
			document.userListForm.submit();
		}
	}
	
	function deleteUsers(){
		var message = "<fmt:message key='common.message.wDelete'/>";
		if(checkForm(message) && confirm("<fmt:message key='common.message.delete'/>")){
			document.userListForm.action = "./user.do?action=deleteUsers";
			document.userListForm.target = "userListFrame";
			document.userListForm.submit();
		}
	}
	
	function initPage(){
		if("<c:out value='${stopResult}'/>" == 1){
			alert("<fmt:message key='common.message.stopSuccess'/>");
		}
		if("<c:out value='${deleteResult}'/>" == 1){
			alert("<fmt:message key='common.message.deleteSuccess'/>");
		}
	}
-->
</script>
</head>
<body onload="initPage()">
<form name="userListForm" action="" method="post">
	<table class="table_title2">
		<tr>
			<td class="title_lab">
				<fmt:message key='user.title.main'/>
			</td>
		</tr>
		<tr>
			<td valign="bottom" class="a_tools" style="padding-left: 3px;height: 30px;"><fmt:message key="user.lable.userType"/>
				<select id="isActivity" name="isActivity">
					<option value="1" <c:if test='${isActivity == 1}'>selected</c:if> >
						<fmt:message key="user.select.activity"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					</option>
					<option value="0" <c:if test='${isActivity == 0}'>selected</c:if> ><fmt:message key="user.select.stop"/></option>
				</select>
				<a class="search" href="javascript:selectUserType();" title="查询" hidefocus="true">查询</a>
				|
				<a class="add" href="javascript:addUser();" title="<fmt:message key='common.button.add'/>" hidefocus="true"><fmt:message key='common.button.add'/></a>
				<a class="update" href="javascript:updateUser();" title="<fmt:message key='common.button.update'/>" hidefocus="true"><fmt:message key='common.button.update'/></a>
				<c:if test="${isActivity == 1}">
				<a class="closestage" href="javascript:stopUsers();" title="<fmt:message key='common.button.stop'/>" hidefocus="true"><fmt:message key='common.button.stop'/></a>
				</c:if>
				<a class="del" href="javascript:deleteUsers();" title="<fmt:message key='common.button.delete'/>" hidefocus="true"><fmt:message key='common.button.delete'/></a>
			</td>
		</tr>
		<tr><td height="2"></td></tr>
		<tr>
			<td>
				<table class="table_style">
					<tr>
						<td class="title" width="8"></td>
						<td class="title" width="30"><fmt:message key='common.lable.checkbox'/></td>
						<td class="title" width="15%"><fmt:message key='user.lable.userCode'/></td>
						<td class="title" width="15%"><fmt:message key='user.lable.userName'/></td>
						<td class="title" width="15%"><fmt:message key='user.lable.deptName'/></td>
						<td class="title" width="15%"><fmt:message key='user.lable.roleName'/></td>
						<td class="title">Email</td>
					</tr>
					<c:forEach var="user" items="${users}">
					<tr onmouseover="onmousemoveChange(this,'img${user.id}')" onmouseout="onmouseoutChange(this,'img${user.id}')">
						<td height="16" width="8" align="right"><img id="img${user.id}" src="./images/table_sign2.bmp"></td>
						<td><input id="id" name="id" type="checkbox" value="${user.id}"/></td>
						<td>${user.userCode}</td>
						<td><a href="javascript:viewUser(${user.id});">${user.userName}</a></td>
						<td>${user.deptName}</td>
						<td>${user.roleName}</td>
						<td>${user.email}</td>
					</tr>
					</c:forEach>
				</table>
			</td>
		</tr>
		<tr>
			<td valign="top">
				<!-- page -->
				<table class="table_page">
					<tr>
						<td class="a_tools">
							${totalRows}&nbsp;<fmt:message key='common.page.totalRow'/>&nbsp;&nbsp;
							<fmt:message key='common.page.totalPage'/>&nbsp;${totalPages}&nbsp;<fmt:message key='common.page'/>&nbsp;&nbsp;
							<fmt:message key='common.page.current'/>&nbsp;${currentPage}&nbsp;<fmt:message key='common.page'/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
							<a href="./user.do?action=userList&flag=1&deptId=${deptId}&isActivity=${isActivity}" target="userListFrame" hidefocus="true"><fmt:message key='common.page.first'/></a>&nbsp;&nbsp;
							<a href="./user.do?action=userList&flag=2&deptId=${deptId}&isActivity=${isActivity}" target="userListFrame" hidefocus="true"><fmt:message key='common.page.previous'/></a>&nbsp;&nbsp;
							<a href="./user.do?action=userList&flag=3&deptId=${deptId}&isActivity=${isActivity}" target="userListFrame" hidefocus="true"><fmt:message key='common.page.next'/></a>&nbsp;&nbsp;
							<a href="./user.do?action=userList&flag=4&deptId=${deptId}&isActivity=${isActivity}" target="userListFrame" hidefocus="true"><fmt:message key='common.page.last'/></a>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
	<input id="deptId" name="deptId" type="hidden" value="${deptId}"/>
	<input id="isActivity" name="isActivity" type="hidden" value="${isActivity}"/>
</form>
</body>
</html>